<template>
  <div class="custom-form">
    <el-row :gutter="15">
      <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
        <el-col :span="8" v-if="hasFormPermission('F_PurchaseOrder')">
          <el-form-item label="采购单号" prop="F_PurchaseOrder">
            <el-input v-model="formData['F_PurchaseOrder']" placeholder="采购单号"
              :disabled="hasDisabledPermission('F_PurchaseOrder',undefined)"
              :readonly="!hasEditPermission('F_PurchaseOrder',true)" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="hasFormPermission('F_SourceNumber')">
          <el-form-item label=" 采购申请单号" prop="F_SourceNumber">
            <el-input v-model="formData['F_SourceNumber']" placeholder="请输入 采购申请单号"
              :disabled="hasDisabledPermission('F_SourceNumber',false)"
              :readonly="!hasEditPermission('F_SourceNumber',false)" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="hasFormPermission('F_PurchaseDate')">
          <el-form-item label="单据日期" prop="F_PurchaseDate">
            <el-date-picker :disabled="hasDisabledPermission('F_PurchaseDate',false)"
              :readonly="!hasEditPermission('F_PurchaseDate',false)" v-model="formData['F_PurchaseDate']"
              format="yyyy-MM-dd" value-format="yyyy-MM-dd" :style="{width: '100%'}" placeholder="请选择单据日期"
              clearable></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="hasFormPermission('F_PurchasePeople')">
          <el-form-item label="采购人员" prop="F_PurchasePeople">
            <el-input v-model="formData['F_PurchasePeople']" placeholder="请输入采购人员"
              :disabled="hasDisabledPermission('F_PurchasePeople',false)"
              :readonly="!hasEditPermission('F_PurchasePeople',false)" clearable
              :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="hasFormPermission('F_DeliveryUnit')">
          <el-form-item label="供货单位" prop="F_DeliveryUnit">
            <el-select v-model="formData.F_DeliveryUnit" placeholder="请选择供货单位"
              :disabled="hasDisabledPermission('F_DeliveryUnit',false)"
              :readonly="!hasEditPermission('F_DeliveryUnit',undefined)" filterable clearable
              :style="{width: '100%'}" remote :remote-method="getF_DeliveryUnitOptions"
              @change="handlerSelectF_DeliveryUnit" :loading="F_DeliveryUnitLoading">
              <el-option v-for="(item, index) in F_DeliveryUnitOptions" :key="index" :label="item.F_FullName"
                :value="item.F_Id" :disabled="item.disabled"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="hasFormPermission('F_PurchaseType')">
          <el-form-item label="采购类型" prop="F_PurchaseType">
            <el-select v-model="formData['F_PurchaseType']" placeholder="请选择采购类型"
              :disabled="hasDisabledPermission('F_PurchaseType',false)"
              :readonly="!hasEditPermission('F_PurchaseType',undefined)" filterable clearable
              :style="{width: '100%'}" @change="handlerSelectF_PurchaseType">
              <el-option v-for="(item, index) in F_PurchaseTypeOptions" :key="index" :label="item.F_ItemName"
                :value="item.F_ItemValue" :disabled="item.disabled"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="hasFormPermission('F_DeliveryDate')">
          <el-form-item label="到货日期" prop="F_DeliveryDate">
            <el-date-picker :disabled="hasDisabledPermission('F_DeliveryDate',false)"
              :readonly="!hasEditPermission('F_DeliveryDate',false)" v-model="formData['F_DeliveryDate']"
              format="yyyy-MM-dd" value-format="yyyy-MM-dd" :style="{width: '100%'}" placeholder="请选择到货日期"
              clearable></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="hasFormPermission('F_TotalPurchases')">
          <el-form-item label="采购总额" prop="F_TotalPurchases">
            <el-input v-model="formData['F_TotalPurchases']" placeholder="请输入采购总额"
              :disabled="hasDisabledPermission('F_TotalPurchases',false)"
              :readonly="!hasEditPermission('F_TotalPurchases',false)" clearable
              :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="hasFormPermission('F_PaymentDate')">
          <el-form-item label=" 付款期限" prop="F_PaymentDate">
            <el-date-picker :disabled="hasDisabledPermission('F_PaymentDate',false)"
              :readonly="!hasEditPermission('F_PaymentDate',false)" v-model="formData['F_PaymentDate']"
              format="yyyy-MM-dd" value-format="yyyy-MM-dd" :style="{width: '100%'}" placeholder="请选择 付款期限"
              clearable></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="hasFormPermission('F_PaymentMethod')">
          <el-form-item label="付款方式" prop="F_PaymentMethod">
            <el-select v-model="formData['F_PaymentMethod']" placeholder="请选择付款方式"
              :disabled="hasDisabledPermission('F_PaymentMethod',false)"
              :readonly="!hasEditPermission('F_PaymentMethod',undefined)" filterable clearable
              :style="{width: '100%'}">
              <el-option v-for="(item, index) in F_PaymentMethodOptions" :key="index" :label="item.F_ItemName"
                :value="item.F_ItemValue" :disabled="item.disabled"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" >
                <el-form-item label="状态" prop="F_Status" hidden="hidden">
                  <el-select v-model="formData.F_Status" placeholder="状态"
                    :disabled="hasDisabledPermission('F_Status',false)"
                    :readonly="!hasEditPermission('F_Status',undefined)" filterable clearable
                    :style="{width: '100%'}" remote :remote-method="getF_StatusOptions"
                    @change="handlerSelectF_Status">
                    <el-option v-for="(item, index) in F_StatusOptions" :key="index" :label="item.F_FullName"
                      :value="item.F_Id" :disabled="item.disabled"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
        <el-col :span="24">
          <avue-form v-loading="preloadLoading119" element-loading-text="数据预加载中..."
            element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.7)"
            :option="option119" @rowClick="() => console.log('sssssssssss')"  v-model="erp_purchaseorderentry" :disabled="disabled">
            <template slot-scope="{row}" slot="input">
              <el-tag>{{row}}</el-tag>
            </template>
          </avue-form>
        </el-col>
        <el-col :span="24" v-if="hasFormPermission('F_Description')">
          <el-form-item label="备注" prop="F_Description">
            <el-input v-model="formData['F_Description']" type="textarea" placeholder="请输入备注"
              :disabled="hasDisabledPermission('F_Description',false)"
              :readonly="!hasEditPermission('F_Description',false)" :autosize="{minRows: 4, maxRows: 4}"
              :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="hasFormPermission('F_AuditMark')" :hidden=true>
          <el-form-item label="审核状态" prop="F_AuditMark">
            <el-input v-model="formData['F_AuditMark']" placeholder="请输入审核状态"
              :disabled="hasDisabledPermission('F_AuditMark',true)"
              :readonly="!hasEditPermission('F_AuditMark',false)" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="hasFormPermission('F_InvalidMark')" :hidden=true>
          <el-form-item label="状态" prop="F_InvalidMark">
            <el-input v-model="formData['F_InvalidMark']" placeholder="请输入状态"
              :disabled="hasDisabledPermission('F_InvalidMark',true)" hidden:true
              :readonly="!hasEditPermission('F_InvalidMark',true)" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="hasFormPermission('F_CreatorUserId')">
          <el-form-item label="制单人员" prop="F_CreatorUserId" required>
            <avue-information-body :operationVal="operationVal" infoType='user'
              :whetherToRebindSecondaryEditing='false' v-model="formData['F_CreatorUserId']"
              placeholder="当前用户制单人员" :disabled="hasDisabledPermission('F_CreatorUserId',true)"
              :readonly="!hasEditPermission('F_CreatorUserId',true)" :style="{width: '100%'}">
            </avue-information-body>
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="hasFormPermission('F_CreatorTime')">
          <el-form-item label="制单时间" prop="F_CreatorTime">
            <el-date-picker :disabled="hasDisabledPermission('F_CreatorTime',false)"
              :readonly="!hasEditPermission('F_CreatorTime',false)" v-model="formData['F_CreatorTime']"
              format="yyyy-MM-dd" value-format="yyyy-MM-dd" :style="{width: '100%'}" placeholder="请选择制单时间"
              clearable></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="!isWorkflowForm">
          <el-form-item size="large" v-if="isEdit">
            <el-button type="primary" @click="submitForm">提交</el-button>
            <el-button @click="resetForm">重置</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
  </div>
</template>
<script>

        import FilterableDataList from '@/components/generator/clientComponents/FilterableDataList.vue';
        import workflowFormAuthorize from "@/mixins/workflowFormAuthorize";
        import authorizeMixin from "@/mixins/authorize";
        import { baseUrl } from "@/config/env";
        import request from "@/router/axios";
        export default {
          mixins: [authorizeMixin,workflowFormAuthorize],
       
  components: {},
  props: ['keyValue', 'isEdit', 'disabled'],
  data() {
    let _this = this
    return {
      showForm: true,
      operationVal: 'add',
      isAdd: true,
      addressUrl:'erp_purchaseorderinfo3',
      mainTableName: 'erp_purchaseorder',
      formConfig: {
        "fields": [{
          "__vModel__": "F_PurchaseOrder",
          "__config__": {
            "label": "采购单号",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "autoCode",
            "span": 8,
            "autoCodeRule": "DocunNumber",
            "formId": 104
          }
        }, {
          "__vModel__": "F_SourceNumber",
          "__config__": {
            "label": " 采购申请单号",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input",
            "span": 8,
            "formId": 111
          }
        }, {
          "tempType": "date",
          "__vModel__": "F_PurchaseDate",
          "__config__": {
            "label": "单据日期",
            "tag": "el-date-picker",
            "avueType": "datetime",
            "showLabel": true,
            "span": 8,
            "formId": 107
          }
        }, {
          "__vModel__": "F_PurchasePeople",
          "__config__": {
            "label": "采购人员",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input",
            "span": 8,
            "formId": 106
          }
        }, {
          "__vModel__": "F_DeliveryUnit",
          "__config__": {
            "label": "供货单位",
            "showLabel": true,
            "tag": "el-select",
            "avueType": "asso-select",
            "filterable": true,
            "span": 8,
            "dataType": "dataSql",
            "autoBindFields": "",
            "formId": 112,
            "database": "localDB",
            "sql": "\tselect i.F_Id,F_FullName from erp_inoutunit i where i.F_UniType=1",
            "showField": "F_FullName",
            "saveField": "F_Id"
          }
        }, {
          "__vModel__": "F_PurchaseType",
          "__config__": {
            "label": "采购类型",
            "showLabel": true,
            "tag": "el-select",
            "avueType": "asso-select",
            "filterable": true,
            "span": 8,
            "dataType": "dataItem",
            "autoBindFields": "",
            "formId": 101,
            "dataItem": "Purchase-category"
          }
        }, {
          "tempType": "date",
          "__vModel__": "F_DeliveryDate",
          "__config__": {
            "label": "到货日期",
            "tag": "el-date-picker",
            "avueType": "datetime",
            "showLabel": true,
            "span": 8,
            "formId": 113
          }
        }, {
          "__vModel__": "F_TotalPurchases",
          "__config__": {
            "label": "采购总额",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input",
            "span": 8,
            "formId": 114
          }
        }, {
          "tempType": "date",
          "__vModel__": "F_PaymentDate",
          "__config__": {
            "label": " 付款期限",
            "tag": "el-date-picker",
            "avueType": "datetime",
            "showLabel": true,
            "span": 8,
            "formId": 103
          }
        }, {
          "__vModel__": "F_PaymentMethod",
          "__config__": {
            "label": "付款方式",
            "showLabel": true,
            "tag": "el-select",
            "avueType": "select",
            "span": 8,
            "formId": 102,
            "dataType": "dataItem",
            "dataItem": "Client_PaymentMode"
          }
        }, {
          "tempType": "default",
          "__config__": {
            "componentName": "table",
            "componentTitle": "商品信息",
            "layoutTree": true,
            "dataType": "",
            "span": 24,
            "formId": 119,
            "children": [{
              "__vModel__": "F_GoodsId",
              "__config__": {
                "label": "商品id",
                "showLabel": true,
                "tag": "el-input",
                "avueType": "input",
                "span": 8,
                "bindTable": "erp_purchaseorderentry",
                "bindTableField": "F_GoodsId"
              }
            }, {
              "__vModel__": "F_GoodsName",
              "__config__": {
                "label": "商品名称",
                "showLabel": true,
                "tag": "el-input",
                "avueType": "input",
                "span": 8,
                "bindTable": "erp_purchaseorderentry",
                "bindTableField": "F_GoodsName"
              }
            }, {
              "__vModel__": "F_GoodCode",
              "__config__": {
                "label": "商品编号",
                "showLabel": true,
                "tag": "el-input",
                "avueType": "input",
                "span": 8,
                "bindTable": "erp_purchaseorderentry",
                "bindTableField": "F_GoodCode"
              }
            }, {
              "__vModel__": "F_Specs",
              "__config__": {
                "label": "规格型号",
                "showLabel": true,
                "tag": "el-input",
                "avueType": "input",
                "span": 8,
                "bindTable": "erp_purchaseorderentry",
                "bindTableField": "F_Specs"
              }
            }, {
              "__vModel__": "F_UnitId",
              "__config__": {
                "label": " 单位",
                "showLabel": true,
                "tag": "el-select",
                "avueType": "select",
                "span": 8,
                "bindTable": "erp_purchaseorderentry",
                "bindTableField": "F_UnitId",
                "dataType": "dataItem",
                "dataItem": "入库单位"
              }
            }, {
              "__vModel__": "F_Quantity",
              "__config__": {
                "label": "数量",
                "showLabel": true,
                "tag": "el-input",
                "avueType": "number",
                "span": 8,
                "bindTable": "erp_purchaseorderentry",
                "bindTableField": "F_Quantity"
              }
            }, 
            {
              "__vModel__": "F_NoReceiptQua",
              "__config__": {
                "label": "未入库数量",
                "showLabel": true,
                "tag": "el-input",
                "avueType": "number",
                "span": 8,
                "bindTable": "erp_purchaseorderentry",
                "bindTableField": "F_NoReceiptQua"
              }
            },
            {
              "__vModel__": "F_ReceiptQua",
              "__config__": {
                "label": "已入库数量",
                "showLabel": true,
                "tag": "el-input",
                "avueType": "number",
                "span": 8,
                "bindTable": "erp_purchaseorderentry",
                "bindTableField": "F_ReceiptQua"
              }
            }, 
             {
              "tempType": "number",
              "__vModel__": "F_UnitPrice",
              "computationalConfiguration": [],
              "prepend": "¥",
              "__config__": {
                "label": "单价",
                "showLabel": true,
                "tag": "el-input",
                "avueType": "input",
                "span": 8,
                "bindTable": "erp_purchaseorderentry",
                "bindTableField": "F_UnitPrice"
              }
            }, {
              "tempType": "number",
              "__vModel__": "F_Amount",
              "computationalConfiguration": [],
              "prepend": "¥",
              "__config__": {
                "label": "金额",
                "showLabel": true,
                "tag": "el-input",
                "avueType": "input",
                "span": 8,
                "bindTable": "erp_purchaseorderentry",
                "bindTableField": "F_Amount"
              }
            }, {
              "__vModel__": "F_Des",
              "__config__": {
                "label": "说明信息",
                "showLabel": true,
                "tag": "el-input",
                "avueType": "input",
                "span": 8,
                "bindTable": "erp_purchaseorderentry",
                "bindTableField": "F_Des"
              }
            }]
          }
        }, {
          "tempType": "textarea",
          "__vModel__": "F_Description",
          "__config__": {
            "label": "备注",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "textarea",
            "span": 24,
            "formId": 128
          }
        }, {
          "__vModel__": "F_AuditMark",
          "__config__": {
            "label": "审核状态",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input",
            "span": 12,
            "formId": 131
          }
        }, {
          "__vModel__": "F_InvalidMark",
          "__config__": {
            "label": "状态",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input",
            "span": 12,
            "formId": 132
          }
        }, {
          "__vModel__": "F_CreatorUserId",
          "__type__": "info",
          "infoType": "user",
          "__organize__": true,
          "__config__": {
            "label": "制单人员",
            "showLabel": true,
            "tag": "avue-information-body",
            "span": 12,
            "whetherToRebindSecondaryEditing": false,
            "formId": 129,
            "placeholder": "当前用户"
          }
        }, {
          "tempType": "date",
          "__vModel__": "F_CreatorTime",
          "__config__": {
            "label": "制单时间",
            "tag": "el-date-picker",
            "avueType": "datetime",
            "showLabel": true,
            "span": 12,
            "formId": 130
          }
        }]
      },
      formData: {
        'F_PurchaseOrder': '',
        'F_SourceNumber': '',
        'F_PurchaseDate': null,
        'F_PurchasePeople': '',
        'F_DeliveryUnit': '',
        'F_PurchaseType': '',
        'F_DeliveryDate': null,
        'F_TotalPurchases': '',
        'F_PaymentDate': null,
        'F_PaymentMethod': '',
        'F_Description': '',
        'F_AuditMark': 1,
        'F_InvalidMark': "1",
        'F_CreatorUserId': '',
        'F_CreatorTime': null,
      },
      rules: {
        F_PurchaseOrder: [{
          required: true,
          message: '采购单号',
          trigger: 'blur'
        }],
        F_PurchaseDate: [{
          required: true,
          message: '请选择单据日期',
          trigger: 'change'
        }],
        F_PurchasePeople: [{
          required: true,
          message: '请输入采购人员',
          trigger: 'blur'
        }],
        F_DeliveryUnit: [{
          required: true,
          message: '请选择供货单位',
          trigger: 'change'
        }],
        F_PurchaseType: [],
        F_DeliveryDate: [{
          required: true,
          message: '请选择到货日期',
          trigger: 'change'
        }],
        F_TotalPurchases: [
          {
          required: true,
          message: '请输入采购总额',
          trigger: 'blur'
          }
        ],
        F_PaymentDate: [{
          required: true,
          message: '请选择付款期限',
          trigger: 'change'
        }],
        F_PaymentMethod: [{
          required: true,
          message: '请选择付款方式',
          trigger: 'change'
        }],
        F_Description: [],
        F_AuditMark: [{
          required: true,
          message: '请输入审核状态',
          trigger: 'blur'
        }],
        F_InvalidMark: [{
          required: true,
          message: '请输入状态',
          trigger: 'blur'
        }],
        F_CreatorTime: [],
      },
      F_DeliveryUnitOptions: [],
      F_DeliveryUnitLoading: false,
      F_PurchaseTypeOptions: [],
      F_PurchaseTypeLoading: false,
      F_PaymentMethodOptions: [],
      option119: {
        submitBtn: false,
        emptyBtn: false,
        labelWidth: 100,
        disabled: !':disabled="disabled"',
        column: [{
          label: '商品信息',
          prop: 'erp_purchaseorderentry',
          type: 'dynamic',
          span: 24,
          children: {
            align: 'center',
            headerAlign: 'center',
            rowAdd: (done) => {
              // this.$message.success('新增回调');
              done({});
            },
            rowDel: (row, done) => {
              // this.$message.success('删除回调'+JSON.stringify(row));
              done();
            },
            column: [{
              label: '商品id',
              hide:true,
              prop: 'F_GoodsId',
              type: 'input',
            }
            , {
              label: '商品名称',
              prop: 'F_GoodsName',
              type: 'input',
            }, {
              label: '商品编号',
              prop: 'F_GoodCode',
              type: 'input',
            }, {
              label: '规格型号',
              prop: 'F_Specs',
              type: 'input',
            }, {
              label: ' 单位',
              type: 'select',
              prop: 'F_UnitId',
              props: {
                 label: 'F_FullName',
                value: 'F_Id'
              },
              dicUrl:  baseUrl + '/erp_purchaserequsetinfo2/unit' 
            }, {
              label: '数量',
              prop: 'F_Quantity',
              type: 'number',
            },
            {
              label: '已入库数量',
              prop: 'F_ReceiptQua',
              disabled:true,
              type: 'number',
            },
            {
              label: '未入库数量',
              prop: 'F_NoReceiptQua',
              disabled:true,
              type: 'number',
            },
             {
              label: '单价',
              prop: 'F_UnitPrice',
              type: 'input',
            }, {
              label: '金额',
              prop: 'F_Amount',
              type: 'input',
            }, {
              label: '说明信息',
              prop: 'F_Des',
              type: 'input',
            }, ]
          }
        }, ],
      },
      erp_purchaseorderentry: {},
      preloadLoading119: false
    }
  },
  computed: {},
  watch: {
    //计算功能
    erp_purchaseorderentry:{
      handler(){
        this.erp_purchaseorderentry.erp_purchaseorderentry.map(item =>{
          item.F_Amount = item.F_Quantity * item.F_UnitPrice;
          //未入库数量=此次订单数量-已入库数量
          item.F_NoReceiptQua=item.F_Quantity-item.F_ReceiptQua;
        })
      },
      immediate:true,
      deep :true
    }
  },
  created() {},
  async mounted() {
    //TODO   再这里做数据回填 请求表单数据
   
           if(this.keyValue){
              this.isAdd = false;
          }
           if(!this.isAdd&&this.keyValue){
              this.operationVal = 'edit';
              this.showForm = false;
              try {
                let res = await request({
                  url: baseUrl + "/"+this.addressUrl+"/" + this.keyValue,
                  method: "get",
                });
                  
            this.formData = res.data.data.erp_purchaseorder
            
          this.erp_purchaseorderentry.erp_purchaseorderentry = res.data.data.erp_purchaseorderentry
          
        this.erp_purchaseorderentry.erp_purchaseorderentry.forEach(element => {
      });
      
                  this.showForm = true;
              } catch (error) {
                
              }
          }

       
    if (typeof this.getF_PurchaseOrderOptions == "function") {
      await this.getF_PurchaseOrderOptions();
    }
    if (typeof this.getF_DeliveryUnitOptions == "function") {
      await this.getF_DeliveryUnitOptions();
    }
    if (typeof this.getF_PurchaseTypeOptions == "function") {
      await this.getF_PurchaseTypeOptions();
    }
    if (typeof this.getF_PaymentMethodOptions == "function") {
      await this.getF_PaymentMethodOptions();
    }
        if (this.isAdd) {
      await this.preloadData113();
    }
  },
  methods: {
    getFormData() {
      let key = this.mainTableName + 'Entity';
      let returnParams = {};
      returnParams[key] = this.formData;
      return {
        ...returnParams,
        erp_purchaseorderentryEntityList: this.erp_purchaseorderentry.erp_purchaseorderentry,
      };
    },
    submitForm() {
      this.$refs['elForm'].validate(valid => {
        var isPrompt = false;
        var isNull=false;
        if (!valid) return
        this.erp_purchaseorderentry.erp_purchaseorderentry.forEach(element => {});
        //格式化数据
        let newObj = this.getFormData();
        for(var j=0;j<erp_purchaseorderentry.erp_purchaseorderentry.length;j++)
        {
          for(var i=j+1;i<erp_purchaseorderentry.erp_purchaseorderentry.length+1;i++)
          {
            if(this.erp_purchaseorderentry.erp_purchaseorderentry[i]["F_GoodsId"]==this.erp_purchaseorderentry.erp_purchaseorderentry[j]["F_GoodsId"])
            {
              isPrompt=true;
            }
          }
          if(this.erp_purchaseorderentry.erp_purchaseorderentry[j]["F_GoodsId"]<-1)
          {
            isNull=true;
          }
        }
        if(isPrompt)
        {
           this.$confirm("请勿选择重复商品","提示");
           return;
        }
        if(isNull)
        {
          this.$confirm("采购数量为0,请核实","提示");
           return;
        }

        //如果没有传入参数就是新增
        if (!this.keyValue) {

          request({
            url: baseUrl + "/"+this.addressUrl,
            method: "post",
            data : newObj
          }).then((res) => {

            this.$notify({
              title: "成功",
              message: "新增成功",
              type: "success",
            });
             this.$emit("onChange",true)
          });

        }
        else{
         if(this.formData.F_Status==1)
         {
          request({
            url: baseUrl + "/"+this.addressUrl+"/" + this.keyValue,
            method: "put",
            data : newObj
          }).then((res) => {

            this.$notify({
              title: "成功",
              message: "修改成功",
              type: "success",
            });
             this.$emit("onChange",true)
          });
         }
         else
         {
            this.$confirm("已入库和部分入库的订单数量不能修改","提示");
           return;
         }
        }
      })
    },
    resetForm() {
      this.$refs['elForm'].resetFields()
    },
    formatTree(data, valueField, lableField, childField, type) {
      let tree = [];
      data.forEach((node, index) => {
        let newNode = {
          value: node[valueField],
          label: node[lableField],
        };
        if (type) {
          newNode.disabled = node[valueField] == undefined ? true : false
        }
        tree.push(newNode);
        if (node[childField] != null && node[childField].length > 0) {
          newNode.children = (this.formatTree(node[childField], valueField, lableField, childField,
          type));
        }
      }, this);
      return tree;
    },
    
          //辅助工作流 审批(编辑) 预留方法
          handleEdit() {
          },
          
    async getF_PurchaseOrderOptions() {
      // 注意：this.$axios是通过Vue.prototype.$axios = axios挂载产生的
      if (!this.isAdd) { //如果是编辑 不用请求
        return;
      }
      try {
        let resp = await this.$axios({
          method: 'get',
          url:  baseUrl + '/code-rules/PurchaseOrder/gen',
        });
        if (resp.data.data) {
          this.formData.F_PurchaseOrder = resp.data.data;
        }
      }
      catch (error) {}
    },
    async getF_DeliveryUnitOptions(query) {
      // 注意：this.$axios是通过Vue.prototype.$axios = axios挂载产生的
      let keyword = ' ';
      if (query) {
        keyword = query;
      }
      if (query !== '') {
        this.F_DeliveryUnitOptionsLoading = true;
      }
      try {
        if ('dataSql' == 'dataSource') {
          let resp = await
          this.$axios({
            method: 'get',
            url:  baseUrl + '/data-sources/undefined/data/?field=F_FullName&keyword=' +
              keyword
          });
          this.F_DeliveryUnitOptionsLoading = false;
          this.F_DeliveryUnitOptions = resp.data.data;
        }
        else {
          let params = {};
          params.sql = `	select i.F_Id,F_FullName from erp_inoutunit i where i.F_UniType=1`;
          let resp = await
          this.$axios({
            method: 'get',
            params: params,
            url:  baseUrl + '/database-links/localDB/datas'
          });
          this.F_DeliveryUnitOptionsLoading = false;
          this.F_DeliveryUnitOptions = resp.data.data;
        }
      }
      catch (error) {}
    },
    handlerSelectF_DeliveryUnit(val) {
      let autoBindFields = JSON.parse('[]');
      let fields = this.formConfig.fields
      let saveField = 'dataSql' == 'dataItem' ? 'F_ItemValue' : 'F_Id'
      //得对应数据列
      let data = this.F_DeliveryUnitOptions.filter(item => {
        return item[saveField] == val;
      })[0];
      if (!data) {
        return;
      }
      //数据回显
      this.setModelValue(this.formConfig.fields, autoBindFields, data);
    },
    async getF_PurchaseTypeOptions() {
      // 注意：this.$axios是通过Vue.prototype.$axios = axios挂载产生的
      try {
        let resp = await this.$axios({
          method: 'get',
          url:  baseUrl + '/data-items/Purchase-category/detail',
        });
        if (resp.data.data) {
          this.F_PurchaseTypeOptions = resp.data.data;
        }
      }
      catch (error) {}
    },
    handlerSelectF_PurchaseType(val) {
      let autoBindFields = JSON.parse('[]');
      let fields = this.formConfig.fields
      let saveField = 'dataItem' == 'dataItem' ? 'F_ItemValue' : 'undefined'
      //得对应数据列
      let data = this.F_PurchaseTypeOptions.filter(item => {
        return item[saveField] == val;
      })[0];
      if (!data) {
        return;
      }
      //数据回显
      this.setModelValue(this.formConfig.fields, autoBindFields, data);
    },
    async getF_PaymentMethodOptions() {
      // 注意：this.$axios是通过Vue.prototype.$axios = axios挂载产生的
      try {
        let resp = await this.$axios({
          method: 'get',
          url:  baseUrl + '/data-items/Client_PaymentMode/detail',
        });
        if (resp.data.data) {
          this.F_PaymentMethodOptions = resp.data.data;
        }
      }
      catch (error) {}
    },
        async preloadData113() {
      //编辑时 取消预加载
      if (this.keyValue) return;
      this.preloadLoading113 = true;
      // 注意：this.$axios是通过Vue.prototype.$axios = axios挂载产生的
      try {
        let resp = await this.$axios({
          method: 'get',
          url:  baseUrl + '/database-links/localDB/datas',
          params: {
            sql: 'select g.F_Id,g.F_FullName,g.F_EnCode,1 as F_Quantity,0 as F_ReceiptQua,1 as F_NoReceiptQua,g.F_SalePrice as F_Amount,g.F_Specs,g.F_InUnit,c.F_FullName as UnitName,g.F_CostPrice from 	erp_goods g left join erp_unitconvert c on g.F_InUnit=c.F_Id'
          }
        });
        if (resp.data) {
          let {
            data
          } = resp.data
          let dynamic = this.getDicData(data,
            '{"F_GoodsId":"F_Id","F_GoodsName":"F_FullName","F_GoodCode":"F_EnCode","F_Specs":"F_Specs","F_UnitId":"F_InUnit","F_Quantity":"F_Quantity","F_ReceiptQua":"F_ReceiptQua","F_NoReceiptQua":"F_NoReceiptQua","F_UnitPrice":"F_CostPrice","F_Amount":"F_Amount","F_Des":""}'
            );
          this.erp_purchaseorderentry.erp_purchaseorderentry = dynamic;
          this.preloadLoading113 = false;
        }
      }
      catch (error) {}
    },
    getDicData(arr, prestrainFieldsConf) {
      let resultArr = [];
      prestrainFieldsConf = JSON.parse(prestrainFieldsConf) || {};
      arr.map(item => {
        let _obj = {};
        for (let key in prestrainFieldsConf) {
          _obj[key] = item[prestrainFieldsConf[key]];
        }
        resultArr.push(_obj);
      });
      return resultArr;
    }
  }
}

</script>
<style>
.el-table__empty-block {
  width: 100% !important;
}

.avue-form__row {
  padding: 0 !important;
}

</style>
